package cn.gailvlun.gll.presentation.xroom.adapter

import android.content.Context
import cn.gailvlun.gll.R
import cn.gailvlun.gll.bean.SelectHolder
import cn.gailvlun.gll.net.cross.GetTagRes
import com.github.markzhai.recyclerview.SingleTypeAdapter

class GameEndAdapter: SingleTypeAdapter<SelectHolder<GetTagRes>> {
    constructor(context: Context?) : super(context, R.layout.item_game_end)

    private var lastSelectPos: Int? = null

    fun click(pos: Int) {
        if (pos != lastSelectPos) {
            mCollection[pos].selected = true
            notifyItemChanged(pos)

            lastSelectPos?.apply {
                mCollection[this].selected = false
                notifyItemChanged(this)
            }

            lastSelectPos = pos
        }
    }

    fun getSelectTag(): GetTagRes? {
        return lastSelectPos?.run { mCollection[this].data }
    }
}